@inject('cartService','App\Interfaces\CartService')
@inject('userService','App\Interfaces\UserService')

<?php
$total_number = $cartService->getCartNumber();
?>

@if(strtotime(date("y-m-d h:i:s"))<strtotime("2016-9-11 24:00:00"))
    <!-- start 携程用户专享礼券入口，活动时间2016-9-3 至 2016-9-11 -->
    <style>
        /*fix bug*/
        .right-bar, .right-bar2{
            top:770px;
        }
        .top-activity{
            position: relative;
            height: 120px;
            background-color: #0078e8;
        }
        .top-activity .code-form {
            float: right;
            width: 356px;
            height: 120px;
            background-color: #ff9a00;
            color: #fff;
        }
        .top-activity .code-form .help-static{
            margin:26px 0 10px 10px;
            font-size: 20px;
            font-weight: 100;
        }
        .top-activity .code-form .t-input{
            width: 258px;
            margin-left: 10px;
            padding: 11px 8px;
            background-color: #fff;
            border: 0;
            border-radius: 4px;
            font-size: 16px;
            vertical-align: middle;

        }
        .top-activity .code-form .btn{
            width: 62px;
            height: 40px;
            background-color: #fff;
            line-height:40px;
            color: #ff7800;
            font-size: 18px;
            border:0;
            border-radius: 4px;
            vertical-align: middle;
            cursor: pointer;
        }
        .top-activity .code-form .btn:hover{
            background-color: #f9f9f9;
        }
        .top-activity .code-form .btn:active{
            background-color: #fff;
        }
        .top-activity .close{
            position: absolute;
            top:0;
            left: 50%;
            margin-left: 525px;
            width: 16px;
            height: 16px;
            background-color: #fff;
            line-height: 16px;
            color: #ff7800;
            font-size: 20px;
            font-family: Arial;
            text-align: center;
            cursor: pointer;
        }
    </style>

    <div class="top-activity">
        <div class="inbox">
            <form action="" method="POST" class="J-form code-form" onSubmit="return false;">
                <p class="help-static">请在下方输入“9元游福塔”领取优惠券</p>
                <input class="t-input" type="text" name="code" id="pwd_code" required placeholder="" autocomplete="off">
                <!-- <input type="submit" class="btn" value="确定"> -->
                <input type="button" class="btn" id="J-activationPwd" value="激活" data-back="<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);?>">
            </form>
            <div class="banner">
                <a href="">
                    <img src="{{ URL::asset('/') }}images/activity/banner.jpg" width="694" height="120" alt="">
                </a>
            </div>
            <a title="关闭" class="close" onclick="$(this).closest('.top-activity').slideUp(300,function() {$(this).remove();});">×</a>
        </div>
    </div>

    <script>

        //用户激活优惠口令
        window.onload=function(){

            $('#J-activationPwd').on('click',function(e){

                var parmData = {};

                pwd_code = $('#pwd_code').val();

                parmData.pwd_code = pwd_code;

                if (pwd_code.length==0) { return null; }

                // url = "/my/coupon/activation_pwd/"+pwd_code;
                url = "/my/coupon/activation_pwd/1";

                $.ajax({
                    type: "POST",
                    url: url,
                    data: parmData,
                    dataType: "json",
                    headers: {
                        'X-CSRF-Token': "{{csrf_token()}}"
                    },
                    success: function (msg) {
                        console.log(msg);
                        /*if (msg.status) {

                            alert(msg.message);
                        }*/
                    }
                }); //end ajax
            });


            //激活优惠券回车触发事件
            $(document).keypress(function(e) {
                var actId = document.activeElement.id;
                if (e.which == 13) {

                    if (actId == "pwd_code"){

                        var parmData = {};

                        pwd_code = $('#pwd_code').val();

                        parmData.pwd_code = pwd_code;

                        if (pwd_code.length==0) { return null; }

                        // url = "/my/coupon/activation_pwd/"+pwd_code;
                        url = "/my/coupon/activation_pwd/1";

                        $.ajax({
                            type: "POST",
                            url: url,
                            data: parmData,
                            dataType: "json",
                            headers: {
                                'X-CSRF-Token': "{{csrf_token()}}"
                            },
                            success: function (msg) {
                                console.log(msg);
                                /*if (msg.status) {

                                    alert(msg.message);
                                }*/
                            }
                        }); //end ajax

                    }
                }
            });
        };

    </script>

<!-- end 携程用户专享礼券入口，活动时间2016-9-3 至 2016-9-11 -->
@endif

<div class="header">
    <!--顶部工具条-->
    <div class="h-tools fn-clear">
        <ul class="inbox navlist nav-def">
            <!--顶部右侧-->
            <li class="nav_r navlevel last">
                <span class="sep">|</span><a>更多<span class="caret-b transform"></span></a>
                <ul class="subnav subnav-r">
                    <li>
                        <a target="_blank" href="http://weibo.com/">新浪微博</a>
                        <div class="code-pic">
                            <img src="{{ URL::asset('/') }}images/2dcode-wb.jpg" alt="">
                            <span class="caret-r"><span class="caret-r"></span></span>
                        </div>
                    </li>
                    <li>
                        <a href="javascript:;">微信公众号</a>
                        <div class="code-pic">
                            <img src="{{ URL::asset('/') }}images/2dcode-wb.jpg" alt="">
                            <span class="caret-r"><span class="caret-r"></span></span>
                        </div>
                    </li>
                </ul>
            </li>

            <li class="nav_r navlevel">
                <span class="sep">|</span><a href="javascript:;">大象票务</a>
                <ul class="subnav">
                    <li><a href="#"><img class="fn-mt10 fn-mb10" src="{{ URL::asset('/') }}images/qr-ticket.jpg" height="120" width="120"></a></li>
                </ul>
            </li>
            <li class="nav_r navlevel">
                <span class="sep">|</span><a href="javascript:;">中原福塔</a>
                <ul class="subnav">
                    <li><a href="#"><img class="fn-mt10 fn-mb10" src="{{ URL::asset('/') }}images/qr-futa.jpg" height="120" width="120"></a></li>
                </ul>
            </li>

            <li class="nav_r"><a href="/help/notice">消费者告知书</a></li>
            <li class="nav_r navlevel">
                <span class="sep">|</span><a>客户服务<span class="caret-b transform"></span></a><span class="sep">|</span>
                <ul class="subnav">
                    <li><a href="http://wpa.qq.com/msgrd?v=3&uin=3039215126&site=qq&menu=yes" target="_blank">联系客服</a></li>
                    <li><a href="/help/common" target="_blank">帮助中心</a></li>
                </ul>
            </li>

            <li class="nav_r navlevel">
                <span class="sep">|</span><a href="/my/center">个人中心<span class="caret-b transform"></span></a><span class="sep">&nbsp;</span>
                <ul class="subnav">
                    <li><a href="/my/order">我的订单</a></li>
                    <li><a href="/my/collection">我的收藏</a></li>
                    <li><a href="/my/coupon ">我的优惠券</a></li>
                    <li><a href="/my/address">收货地址</a></li>
                    <li><a href="/my/account_safe">账号安全</a></li>
                </ul>
            </li>
            <li class="nav_r"><a href="/my/order">我的订单</a></li>
            <!--END/顶部右侧-->


            <!--顶部左侧-->
            @if (!Auth::check())
                <li class="nav_l"><span class="fn-mr10">欢迎来到阿福易购</span><span class="sep">|</span></li>
                <li class="nav_l"><a href="/user/login">请登录</a><span class="sep">|</span></li>
                <li class="nav_l"><a href="/user/register">快速注册</a></li>
            @else
                @if (Session::get('user_name'))
                    <li class="nav_l"><span class="fn-mr10">你好,</span><span class="text-color-1 fn-ml4 fn-mr10">{{Session::get('user_name')}}</span><span class="sep">|</span></li>
                    <li class="nav_l"><a href="/user/logout">退出</a></li>
                @else
                    <li class="nav_l"><span class="fn-mr10">你好,</span><span class="text-color-1 fn-ml4 fn-mr10">{{Auth::user()->user_name}}</span><span class="sep">|</span></li>
                    <li class="nav_l"><a href="/user/logout">退出</a></li>
                @endif
            @endif

            <li class="nav_l navlevel">
                <span class="sep">|</span><a href="javascript:;"><span class="icon icon-mobile"></span>手机客户端</a>
                <ul class="subnav">
                    <li><a href="#"><img class="fn-mt10 fn-mb10" src="{{ URL::asset('/') }}images/qr.png" height="120" width="120"></a></li>
                </ul>
            </li>
            <!--END/顶部左侧-->
        </ul>
    </div>
    <!--END/顶部工具条-->

   <!-- header1-->

        <!--LOGO-->
        <div class="logo-wrap">
            <a href="/">
                <img class="logo" src="{{ URL::asset('/') }}images/logo.jpg" alt="logo">
            </a>
        </div>
        <!--END/LOGO-->
    </div>
    <!--END/顶部搜索&LOGO-->

    @if( !isset($noTopNav) )
    <!--顶部导航-->

        @inject('categoryService','App\Interfaces\CategoryService')
        @inject('brandService','App\Interfaces\BrandService')
        @inject('pictureService','App\Interfaces\PictureService')

        <div id="hNav" class="h-nav fn-clear">
            <ul class="inbox navlist nav-orange fn-rel">
                <!--<i class="icon icon-rline"></i>-->
                <li class="@if(Request::path()=='/' ) cur @endif"><a href="/">首页</a></li>
                @foreach($categoryService->getTree() as $cat)
                    <?php //echo $cat->children;?>

                    <li class="@if(Request::path()=='cat/'.$cat->cat_id ) cur @endif">
                        <a href="/cat/{{$cat->cat_id}}" target="_blank">{{$cat->cat_name}}</a>
                        @if(count($cat->children)>0)
                        <div class="subtype">
                            <div class="subnav-r">
                                <div class="tit tit-2 tit-skin-2"><span class="h">热卖品牌</span></div>
                                <ul class="hot-brand-list fn-dib">

                                    <?php
                                    $catRecommendBrands=$brandService->getCatRecommendBrands($cat->cat_id);
                                    ?>
                                    @if(count($catRecommendBrands)>0)
                                        @foreach($catRecommendBrands as $k=>$v)

                                            <li>
                                                <a href="/search?keyword={{$v->brand_name}}" target="_blank">
                                                    <img src="{{$pictureService::thumb($v->brand_logo,56,38)}}" alt="{{$v->brand_name}}" title="{{$v->brand_name}}">
                                                </a>
                                            </li>
                                        @endforeach
                                    @endif
                                </ul>
                            </div>
                            <ul class="subnav-l link-list link-list-skin1">
                                @foreach($cat->children as $child)
                                    <li>
                                        <a class="p-type">
                                            <span class="w-5em fn-dib-otw" title="{{$child->cat_name}}">{{str_limit($child->cat_name, 10, '...')}} </span>
                                            <i class="icon icon-arrow-r2"></i>
                                        </a>
                                        <p class="c-type-wrap">
                                            @foreach($child->children as $grandChild)
                                                <a class="c-type @if(@$grandChild->cat_id==@$_REQUEST['cat_id']) hover @endif" href="/cat/{{$grandChild->cat_id}}?cat_id={{$grandChild->cat_id}}" target="_blank">{{$grandChild->cat_name}}</a>
                                            @endforeach
                                            <span class="borb"></span>
                                        </p>
                                    </li>
                                @endforeach
                            </ul>

                        </div>
                        @endif
                    </li>

                @endforeach
                <li class="sub-cart">
                    <a target="_blank" href="/cart" class="t-shopcart">
                        <i class="icon icon-cart fn-mt4"></i>
                        <span class="wrap js-cart">购物车<b class="num fn-dib cart-num">{{$total_number}}</b></span>
                    </a>
                </li>

            </ul>
        </div>
        <!--END/顶部导航-->
    @endif
</div>